package com.properties.test.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.properties.test.config.DemoProperties;
import com.properties.test.vo.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("demo")
public class DemoController {
    @Autowired
    DemoProperties demoProperties;
    @ResponseBody
    @GetMapping("/test")
    public String test(){
        log.info("properties:{}", JSONObject.toJSONString(demoProperties));
        return JSONObject.toJSONString(demoProperties);
    }
    @GetMapping("/list")
    public List<UserInfo> list() throws JsonProcessingException {

        ArrayList<UserInfo> list = new ArrayList<UserInfo>() {{
            add(new UserInfo("张三", 10, "测试"));
            add(new UserInfo("张三2", 30, "ccc"));
        }};
        ObjectMapper mapper = new ObjectMapper();
        System.out.println(mapper.writeValueAsString(list));
        return list;
    }

}
